#ifndef MESSAGE_BOX_H
#define MESSAGE_BOX_H

#define MAX_EXPAND_NUM 10

enum message_box_state
{
    MSG_BOX_INIT=1,  // just init a msg_box
    MSG_BOX_ADD,   // finishing the msg's loading
    MSG_BOX_EXPAND,	//begin to add msg's record , at that time the message head can't be set
    MSG_BOX_DEAL,	//begin to add msg's expand , at that time the message head can't be set  ,and we can't add record again
    MSG_BOX_LOADDATA=0x1000,    // read data to the msg box, if all the data were read,change state to MSG_BOX_REBUILD
    MSG_BOX_REBUILDING,
    MSG_BOX_RECOVER,  	//finish the record set and expand set, now the message can output data
    MSG_BOX_CUT, // load message box's head
    MSG_BOX_READ,
    MSG_BOX_ERROR=0xffff,
};

struct message_box
{
	MSG_HEAD head;	 // a fixed size structure to store the message's head
	void * head_template;    // this is the struct template of the head
	void * record_template;  // this is the struct template of the record in this message
	int box_state;           // it show what process_state this message_box  in
	int head_size;		 // it means the message head's size
	BYTE ** record;          // a pointer array to store the record (bin blob format), most time it should be null
	void ** precord;         // a pointer array to store the pointers which point to the record struct in memory
	int * record_size;       // an int value array to store each record's bin blob size 
	BYTE ** expand;   // a fixed size pointer array to store the expand(bin blob format),most time it should be null
	void ** pexpand;  // a fixed size pointer array to store the pointers which point to the expand struct in memory
	int * expand_size;  // an int value array to store each expand's bin blob size
	void * blob;             // the data blob of the message record and/or the message expand, do not include the head.
	int current_offset;      // an int value to show the current offset of the data blob. used when we deal with the data blob  
	void * policy;		// a policy describe the local route
	void * active_msg;  	// this is the message that active this message, 
				//  should be null if the message is received from connector_proc,
				//  generated by monitor or 
				//  addin want to hide the active message.
	void * path_site;	// this point to message's current path site
}__attribute__((packed));

int __message_add_record_site(void * message,int increment);
int __message_alloc_record_site(void * message);
void * message_get_expand_template();

struct tag_msg_kits
{
	int type;
	void * head_template;
	void * expand_head_template;
	void * expand_bin_template;
};

#endif
